<?php
class Mod_modules extends CI_Model 
{
    function __construct()
    {
        parent::__construct();
    }
	
	function get_module_name($module_id)
	{
		$query = $this->db->get_where(PREFIX_TABLE.'modules', array('module_id' => $module_id), 1);
		
		if ($query->num_rows() ==1)
		{
			$row = $query->row();
			return $this->lang->line($row->name_lang_key);
		}
		
		return $this->lang->line('error_unknown');
	}
	
	function get_module_desc($module_id)
	{
		$query = $this->db->get_where(PREFIX_TABLE.'modules', array('module_id' => $module_id), 1);
		if ($query->num_rows() ==1)
		{
			$row = $query->row();
			return $this->lang->line($row->desc_lang_key);
		}
	
		return $this->lang->line('error_unknown');	
	}
	
	function get_all_modules()
	{
		$this->db->from(PREFIX_TABLE.'modules');
		$this->db->order_by("sort", "asc");
		return $this->db->get();		
	}
	// Get allow module user
	function get_allowed_modules($user_id)
	{
		$this->db->from(PREFIX_TABLE.'modules');
		$this->db->join(PREFIX_TABLE.'user_access_permissions',PREFIX_TABLE.'access_user_permissions.module_id='.PREFIX_TABLE.'modules.module_id');
		$this->db->where(PREFIX_TABLE."user_access_permissions.use_user_id",$user_id);
		$this->db->order_by("sort", "asc");
		return $this->db->get();		
	}
	
	// Get allow module user group
	function get_allowed_modules_group($group_id)
	{
		$this->db->from(PREFIX_TABLE.'modules');
		$this->db->join(PREFIX_TABLE.'user_access_permissions',PREFIX_TABLE.'access_user_permissions.module_id='.PREFIX_TABLE.'modules.module_id');
		$this->db->where(PREFIX_TABLE."user_access_permissions.use_user_id",$user_id);
		$this->db->order_by("sort", "asc");
		return $this->db->get();		
	}
}
?>
